package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CheckGroupMapper extends BaseMapper<CheckGroup> {
    @Insert("insert into t_checkgroup_checkitem values (#{gid},#{itemId})")
    void addCheckGroupAndCheckItem(@Param("gid") Integer id,@Param("itemId") Integer itemId);

    @Select("select CHECKITEM_ID from t_checkgroup_checkitem where CHECKGROUP_ID = #{gid}")
    int[] findCheckItemIdsByGroupId(@Param("gid") int id);

    @Delete("delete from t_checkgroup_checkitem where CHECKGROUP_ID = #{id}")
    void deleteCheckGroupAndCheckItemById(@Param("id") Integer id);

    @Select("select name from t_checkitem tc join t_checkgroup_checkitem tcc on tc.id = tcc.CHECKITEM_ID" +
            " where tcc.CHECKGROUP_ID = #{id}")
    List<CheckItem> findCheckItemsById(@Param("id") Integer id);
}
